package org.misalen.web.server.controllers.user;

import java.util.HashMap;
import java.util.List;

import org.misalen.annotations.ControllerApi;
import org.misalen.annotations.InterfaceApi;
import org.misalen.web.database.model.mysql.pro.ProUserBanner;
import org.misalen.web.database.model.mysql.sys.SysWordbookItem;
import org.misalen.web.database.util.PaginationFrom;
import org.misalen.web.server.config.ServerResult;
import org.misalen.web.server.config.ServerUrl;
import org.misalen.web.server.controllers.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ControllerApi(value = "通用基础接口", description = "客户端配置", index = 000)
@RequestMapping(value = ServerUrl.UserBasisControllerUrl)
public class UserBasisController extends BaseController {

	@RequestMapping(value = "/config", method = { RequestMethod.POST, RequestMethod.GET })
	@InterfaceApi(value = "初始化配置(返回一些枚举信息,展示用itemName,与后台交互用itemCode)", resultClass = { SysWordbookItem.class })
	public @ResponseBody ServerResult config() {
		List<SysWordbookItem> carrierType = sysWordbookItemRepository
				.findByWbId(sysWordbookRepository.getByCode("sys-carrier-type").getPrimaryKey());
		for (int i = 0; i < carrierType.size(); i++) {
			if (carrierType.get(i).getItemCode().equals("热文")) {
				carrierType.remove(i);
				break;
			}
		}
		PaginationFrom<ProUserBanner> banners = proUserBannerRepository.findPageByBean(new ProUserBanner(),
				new PaginationFrom<ProUserBanner>());
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("sys-carrier-type", carrierType);
		hashMap.put("banner", banners.getList());
		hashMap.put("price-list",
				proPriceListRepository.findPageByHql("from ProPriceList order by money", null, null).getList());
		return ServerResult.ok(hashMap);
	}

}
